package cn.com.headfree.tjfx.controller;

import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.tjfx.dto.StaffRankDto;
import cn.com.headfree.tjfx.service.IStatisticalService;
import com.gta.edu.sdk.common.dto.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: TODO
 * @Author wcSun
 * @Date 2021/9/29
 **/
@RestController
@RequestMapping(value = "/statistical", produces = "application/json;charset=UTF-8")
public class StatisticalController {

    @Autowired
    private IStatisticalService statisticalService;


    /**
     * 信息总览-年龄结构分布
     * @param orgId
     * @return
     */
    @RequestMapping("/aChartAge")
    public ResultData aChartAge(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.aChartAge(orgId));
        return rs;
    }

    /**
     * 年龄结构分析 - 列表
     * @param orgId
     * @return
     */
    @RequestMapping("/ageStructure")
    public ResultData ageStructure(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.ageStructure(orgId));
        return rs;
    }

    /**
     * 年龄结构分析 - 图表
     * @param orgId
     * @return
     */
    @RequestMapping("/ageStructureChar")
    public ResultData ageStructureChar(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.ageStructureChar(orgId));
        return rs;
    }

    /**
     * 年龄结构分析列表导出
     * @param request
     * @param response
     * @param orgId
     */
    @GetMapping("/exportAgeStructureExcel")
    public void exportAgeStructureExcel(HttpServletRequest request, HttpServletResponse response, String orgId) {
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        statisticalService.exportAgeStructureExcel(request,response,orgId);

        // 输出到本地
//        String excelName = "D://export//myExcel.xls";
//        FileOutputStream out = null;
//        try {
//            out = new FileOutputStream(excelName);
//            workbook.write(out);
//            out.flush();
//            out.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if (out != null)
//                try {
//                    out.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            out = null;
//        }
    }


    /**
     * 信息总览-性别分布
     * @param orgId
     * @return
     */
    @RequestMapping("/sexDistribution")
    public ResultData sexDistribution(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.sexDistribution(orgId));
        return rs;
    }

    /**
     * 信息总览-学历分布
     * @param orgId
     * @return
     */
    @RequestMapping("/aChartEducation")
    public ResultData aChartEducation(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.aChartEducation(orgId));
        return rs;
    }

    /**
     * 信息总览-退休趋势分析
     * @param orgId
     * @return
     */
    @RequestMapping("/aChartRetire")
    public ResultData aChartRetire(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.aChartRetire(orgId));
        return rs;
    }


    /**
     * 信息总览-职称分布
     * @param orgId
     * @return
     */
    @RequestMapping("/aChartTitle")
    public ResultData aChartTitle(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.aChartTitle(orgId));
        return rs;
    }


    /**
     * 信息总览-干部分布
     * @param orgId
     * @return
     */
    @RequestMapping("/aChartCadre")
    public ResultData aChartCadre(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.aChartCadre(orgId));
        return rs;
    }


    /**
     * 职员职级-图表
     * @param orgId
     * @return
     */
    @RequestMapping("/employeeLevelChar")
    public ResultData employeeLevelChar(String orgId){
        if(StringUtils.isBlank(orgId)){
            orgId = "10347258";
        }
        ResultData rs = new ResultData();
        rs.setData(statisticalService.employeeLevelChar(orgId));
        return rs;
    }

    /**
     * 职员职级-表格
     * @param page
     * @param staffRankDto
     * @return
     */
    @RequestMapping("/employeeLevel")
    public ResultData employeeLevel(Page<StaffRankDto> page, @RequestBody StaffRankDto staffRankDto){
        if(StringUtils.isBlank(staffRankDto.getOrgId())){
            staffRankDto.setOrgId("10347258");
        }
        ResultData rs = new ResultData();
        statisticalService.employeeLevel(page,staffRankDto);
        rs.setData(page);
        return rs;
    }

    /**
     * 职员职级-表格-导出报表
     */
    @GetMapping("/exportemployeeLevelExcel")
    public void exportemployeeLevelExcel(HttpServletRequest request, HttpServletResponse response,StaffRankDto staffRankDto) {
        if(StringUtils.isBlank(staffRankDto.getOrgId())){
            staffRankDto.setOrgId("10347258");
        }
        statisticalService.exportemployeeLevelExcel(request,response,staffRankDto);
    }
}
